<?php
namespace app\api\controller;

use app\common\controller\Init;
use app\api\model\Folder as FolderModel;
use app\api\model\File as FileModel;
use think\Db;
use think\Validate;

class Disk extends Init
{
    /**
     * 创建一级或多级目录
     * @param string $folder
     * @param int $pdir_id
     * @param string $pdir_name
     * @return bool|mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function create() {
        $this->checkRequest('post');
        $Folder = new FolderModel($this->UID);
        $folder = input('?post.folder') == false || trim(input('post.folder')) == '' ? '/' : trim(input('post.folder'));
        $pdir_id = input('?post.pdir_id') == false || (int)input('post.pdir_id') < 1 ? '0' : (int)input('post.pdir_id');
        $folderInfo = $Folder->getById($pdir_id);
        if($Folder->createFolder($folder, $folderInfo['id'], $folderInfo['dir_name']) > 0){
            success('文件夹创建成功');
        } else {
            error('文件夹创建失败',500);
        }
    }

    /**
     * 根据ID删除文件夹
     * @param array $folder_ids
     * @return array|int
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function delete() {
        $Folder = new FolderModel($this->UID);
        return $Folder->delete($folder_ids);
    }

    public function copy() {
        $Folder = new FolderModel($this->UID);
        return $Folder->copy($folder_ids, $Toid);
    }

}
